/*
 * This file is part of the Sx Framework Library.
 * 
 * Copyright (C) 2013 University of Colorado Denver
 * <min.choi@ucdenver.edu> <shane.transue@ucdenver.edu>
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy 
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 
 * copies of the Software, and to permit persons to whom the Software is 
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in 
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
 * DEALINGS IN THE SOFTWARE.
 */
#include <sxMesh.h>

Sx::Graphics::Objects::Mesh::Mesh() : GraphicsObject() {
	this->surface = MappedSurface();
}

Sx::Graphics::Objects::Mesh::Mesh(const Mesh& mesh) {
	static int count = 0;

	this->surface = mesh.surface;
	this->color = mesh.color;
	this->lineSelectionDistance = mesh.lineSelectionDistance;
	this->name = mesh.name;
	this->name.append(String::ValueOf(count));
	this->pointSelectionDistance = mesh.pointSelectionDistance;
	this->selected = mesh.selected;
	this->transform = mesh.transform;
	this->visible = mesh.visible;
}

Sx::Graphics::Objects::Mesh::~Mesh() {}

bool Sx::Graphics::Objects::Mesh::construct() {
	return true;
}

void Sx::Graphics::Objects::Mesh::update(float dt) {
	return;
}

bool Sx::Graphics::Objects::Mesh::addFace(const Primitives::IndiceFace& face) {
	this->surface.addFace(face);
	return true;
}

bool Sx::Graphics::Objects::Mesh::addCoordinate(const Eigen::Vector3f& coordinate) {
	this->surface.addCoordinate(coordinate);
	return true;
}

bool Sx::Graphics::Objects::Mesh::setFace(const Primitives::IndiceFace& face, unsigned int index) {
	return this->surface.setFace(face, index);
}

bool Sx::Graphics::Objects::Mesh::remove(const Primitives::IndiceFace& face) {
	return this->surface.remove(face);
}

bool Sx::Graphics::Objects::Mesh::removeFace(const Primitives::IndiceFace& face) {
	return this->surface.removeFace(face);
}

bool Sx::Graphics::Objects::Mesh::removeFace(unsigned int index) {
	return this->surface.removeFace(index);
}

bool Sx::Graphics::Objects::Mesh::triangulateFaces() {
	return this->surface.triangulateFaces();
}

unsigned int Sx::Graphics::Objects::Mesh::getNumFaces() const {
	return this->surface.getFaceCount();
}

Sx::Graphics::Primitives::IndiceFace Sx::Graphics::Objects::Mesh::getFace(unsigned int index) {
	return this->surface.getFace(index);
}

Sx::Graphics::Util::IndexedFaceArray& Sx::Graphics::Objects::Mesh::getFaces() {
	return this->surface.getFaces();
}

Sx::Graphics::Util::VectorArray& Sx::Graphics::Objects::Mesh::getVertexNormals() {
	return this->surface.getVertexNormals();
}

Sx::Graphics::Util::VectorArray& Sx::Graphics::Objects::Mesh::getFaceNormals() {
	return this->surface.getFaceNormals();
}

Sx::Graphics::Util::VectorArray& Sx::Graphics::Objects::Mesh::getCoordinates() {
	return this->surface.getCoordinates();
}

void Sx::Graphics::Objects::Mesh::setSurface(const MappedSurface& surface) {
	this->surface.clear();
	this->surface.getCoordinates() = surface.getCoordinates();
	this->surface.getFaces() = surface.getFaces();
	this->surface.getVertexNormals() = surface.getVertexNormals();
	this->surface.getFaceNormals() = surface.getFaceNormals();
}

const Sx::Graphics::Objects::MappedSurface& Sx::Graphics::Objects::Mesh::getSurface() const {
	return this->surface;
}
